package com.foreveross.fetl.web.action.preprocess;

import java.util.Date;
import java.util.Map;

import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.dayatang.querychannel.support.Page;
import com.foreveross.fetl.application.IHbasePageApplication;
import com.foreveross.fetl.common.vo.FetlErrorMessage;
import com.foreveross.fetl.util.DateUtils;
import com.foreveross.fetl.util.FetlErrorUtils;
import com.foreveross.fetl.web.action.BaseAction;

@Controller("fetlErrorMessageAction")
@Scope("prototype")
public class FetlErrorMessageAction extends BaseAction {
	
	
	@Inject
	private IHbasePageApplication hbasePageApplication;

	/**
	 * 
	 */
	private static final long serialVersionUID = 4021162039618336063L;
	
	public String pageJson() {
		HttpServletRequest req = ServletActionContext.getRequest();
		String code = req.getParameter("code");
		String start = req.getParameter("start");
		String end = req.getParameter("end");
		Date startTime =null;
		Date endTime=null;
		if(null!=start && !"".equals(start)){
			start=start.replace("-", "").replace(" ", "");
			startTime=DateUtils.parse(start, "yyyyMMddHH");
		}
		if(null!=end && !"".endsWith(end)){
			end=end.replace("-", "").replace(" ", "");
			endTime=DateUtils.parse(end, "yyyyMMddHH");
		}
		Page<FetlErrorMessage> all=hbasePageApplication.pageQuery(code, startTime, endTime, page, pagesize);
		dataMap.put("Rows", all.getResult());
		dataMap.put("start", page * pagesize - pagesize);
		dataMap.put("limit", pagesize);
		dataMap.put("Total", all.getTotalCount());
		return "JSON";
	}
	

	public String list(){
		return "METHOD";
	}

	
	public String nameMapSelect(){
		dataMap.put("data", FetlErrorUtils.fetlNameMap);
		return "JSON";
	}
	
	public String view(){
		return "METHOD";
	}
	
	public String get(){
		HttpServletRequest req = ServletActionContext.getRequest();
		String id=req.getParameter("id");
		dataMap.put("data", hbasePageApplication.getById(id));
		return "JSON";
	}

}
